package com.itheima.service.serviceimpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.flag.Flag;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {
//    @Autowired
//    private DeptMapper deptMapper;

    @Autowired
    private EmpMapper empMapper;
    @Override
    public List<Dept> selectDepts() {
        //结论: 通过super调用父类方法的时候 , 如果该方法中子类没有重写过 , super可以直接省略
        //细节 : 实际上省略的不是super 而是this
//        List<Dept> listService = deptMapper.selectList(null);
//        return listService;
        return super.list();
    }

    @Override
    public void deleteById(Integer id) {
//        deptMapper.deleteById(id);
         super.removeById(id);
    }


    @Override
    public void insertById(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        //保存部门
//        deptMapper.insert(dept);
        super.save(dept);
    }


    @Override
    public Dept getById(Integer id) {
//      Dept dept = deptMapper.selectById(id);
//      return dept;
        return super.getById(id);
    }

    @Override
    public void updateDept(Dept dept) {
        //更新修改过后的时间
//        dept.setUpdateTime(LocalDateTime.now());
//        deptMapper.updateById(dept);
        super.updateById(dept);

    }

}
